﻿@model Wicresoft.SelfService.DAO.ClassifyConfig
@{
    Layout = null;
}
<script type="text/javascript">
    $(function () {
        $(document).ready(function() {
           $("#tbevent1").hide();
           $("#tbevent2").hide();
           $("#tbevent3").hide();
        });
        $("#IsEvent").change(function() 
        {
          var isEvent=$("#IsEvent").find("option:selected").text(); 
          if(isEvent=="是")
          {
             $("#tbevent1").show();
             $("#tbevent2").show();
             $("#tbevent3").show();
          }else
          {
             $("#tbevent1").hide();
             $("#tbevent2").hide();
             $("#tbevent3").hide();
          }
        });


        $("#Applvl1").change(function(){
            var tv1=$("#Applvl1").val();
            var tn1=$("#Applvl1").find("option:selected").val();
            if(tv1!="0")
            {
                $.ajax({
                    url: "../ServiceMaintain/GetTier2List",
                    type: "GET",
                    data: { "tier1": tn1 },
                    success: function (data) {
                        $("#Applvl2").empty();
                        $("#Applvl2").append("<option value=" + 0 + ">" + "--------- 请选择 --------" + "</option>");
                        $.each(data, function (i, item) {
                            //var n = i + 1;
                            $("#Applvl2").append("<option>" + item.valueOf(i) + "</option>");
                        });
                    }
                });

            }
        });

        $("#Applvl2").change(function(){
            var tv1=$("#Applvl1").val();
            var tn1=$("#Applvl1").find("option:selected").val();
            var tv2=$("#Applvl2").val();
            var tn2=$("#Applvl2").find("option:selected").val();
            if(tv2!="0" )
            {
                $.ajax({
                    url: "../ServiceMaintain/GetTier3List",
                    type: "GET",
                    data: { "tier1": tn1,"tier2": tn2 },
                    success: function (data) {
                        $("#Applvl3").empty();
                        $("#Applvl3").append("<option value=" + 0 + ">" + "--------- 请选择 --------" + "</option>");
                        $.each(data, function (i, item) {
                            //var n = i + 1;
                            $("#Applvl3").append("<option>" + item.valueOf(i) + "</option>");
                        });
                    }
                });
            }
        });

        var flag=false;
       
        $("#createBtn").click(function () {
            var ServiceName = $("#ServiceName").val();
            var v1=$("#ServiceID").find("option:selected").val(); 
            if(v1=="0")
            {
                alert("请选择服务申请类别");
                flag = false;
            }
            else if (ServiceName == "") {
                alert("选择分类不能为空！");
                flag=false; 
            }
            else
            {
                $.post("@Url.Action("SearchByServiceName", "ServiceMaintain")", $("#classifyForm").serialize(), 
                function(data){           
                if(data == "true"){
                   flag=true;
                }
                else{
                    alert("该选择分类已存在!");
                    flag=false;
                }
                });
            }

            var isevent=$("#IsEvent").val();
            if(isevent=="1")  //在ITSM中生成事件单
            {
                var tv1=$("#Applvl1").val();
                var tv2=$("#Applvl2").val();
                var tv3=$("#Applvl3").val();
                if(tv1=="0"){
                   alert("请选择事件分类（一）");
                   flag=false;
                }
                else if(tv2=="0"){
                   alert("请选择事件分类（二）");
                   flag=false;
                }
                else if(tv3=="0"){
                   alert("请选择事件分类（三）");
                   flag=false;
                }
            }
            
            if (flag) {
                $.post("@Url.Action("CreateClassify", "ServiceMaintain")", $("#classifyForm").serialize(), 
                function(data){           
                if(data == "true"){
                    alert("创建成功");
                    $("#ServiceName").val("");
                    $("#Applvl1").val("");
                    $("#Applvl2").val("");
                    $("#Applvl3").val("");
                    location.reload();
                }
                else{
                    alert("创建失败");
                }
                });
             }

        });

      

    });
</script>
<div class="right_title">添加服务类别</div>
<div class="right_box_top ui-icons">
</div>
<div class="right_box_bg">
    <div class="right_box">
        <div style="padding-bottom: 20px;">
            @using (Html.BeginForm("CreateClassify", "ServiceMaintain", FormMethod.Post, new { @id = "classifyForm" }))
            {
                <table style="width:100%;">
                <tbody>
                    <tr>
                        <td colspan="4">
                            <b>步骤一：</b>
                        </td>
                    </tr>
                    <tr>
                        <th align="right" style=" width:20%">
                            <label>服务申请类别</label>:
                        </th>
                        <td align="left" style=" width:25%">
                            @{
                                List<SelectListItem> ServiceID = new List<SelectListItem>();
                                ServiceID.Add(new SelectListItem { Text = "--------- 请选择 --------", Value = "0" });
                                foreach (object e in Enum.GetValues(typeof(Wicresoft.SelfService.DAO.ServiceNameID)))
                                {
                                    ServiceID.Add(new SelectListItem { Text = Enum.GetName(typeof(Wicresoft.SelfService.DAO.ServiceNameID), e), Value = ((int)e).ToString() });
                                }
                                @Html.DropDownList("ServiceID", ServiceID);
                            }
                        </td>
                         <th align="right" style=" width:25%">
                            <label>在自服务流程中需审批否？</label>
                        </th>
                        <td align="left" style=" width:30%">
                            @{
                                List<SelectListItem> needapprove = new List<SelectListItem>();
                                foreach (object e in Enum.GetValues(typeof(Wicresoft.SelfService.DAO.YESORNOT)))
                                {
                                    needapprove.Add(new SelectListItem { Text = Enum.GetName(typeof(Wicresoft.SelfService.DAO.YESORNOT), e), Value = ((int)e).ToString() });
                                }
                                @Html.DropDownList("NeedApprove", needapprove);
                            }
                        </td>
                    </tr>
                    <tr>
                        <td colspan="4">
                            <hr />
                        </td>
                    </tr>
                    <tr>
                        <td colspan="4">
                            <b>步骤二：</b>
                        </td>
                    </tr>
                    <tr>
                        <th align="right">
                            <label>选择分类:</label>
                        </th>
                        <td align="left">@Html.EditorFor(model => model.ServiceName, new { id = "ServiceName" })</td>
                        <th align="right">
                            <label>与ITSM事件映射否？</label>
                        </th>
                        <td align="left">
                                @{
                                List<SelectListItem> IsEvent = new List<SelectListItem>();
                                foreach (object e in Enum.GetValues(typeof(Wicresoft.SelfService.DAO.YESORNOT)))
                                {
                                    IsEvent.Add(new SelectListItem { Text = Enum.GetName(typeof(Wicresoft.SelfService.DAO.YESORNOT), e), Value = ((int)e).ToString() });
                                }
                                @Html.DropDownList("IsEvent", IsEvent);
                            }
                        </td>
                    </tr>
                    <tr id="tbevent1">
                        <th align="right">
                            <label>事件分类(一):</label>
                        </th>
                        <td align="left">
                            @{
                                List<SelectListItem> Applvl1 = new List<SelectListItem>();
                                Applvl1.Add(new SelectListItem { Text = "--------- 请选择 --------", Value = "0" });
                                foreach (object e in (IEnumerable<string>)ViewData["Tier1"])
                                {
                                    Applvl1.Add(new SelectListItem { Text = e.ToString() });
                                }
                                @Html.DropDownList("Applvl1", Applvl1);
                            }
                        </td>
                        <td colspan="2"></td>
                    </tr>
                    <tr id="tbevent2">  
                        <th align="right">
                            <label>事件分类(二):</label>
                        </th>
                        <td align="left">
                           @{
                                List<SelectListItem> Applvl2 = new List<SelectListItem>();
                                Applvl2.Add(new SelectListItem { Text = "--------- 请选择 --------", Value = "0" });
                                @Html.DropDownList("Applvl2", Applvl2);
                            }
                        </td>
                        <td colspan="2"></td>
                    </tr>
                    <tr id="tbevent3">
                        <th align="right">
                            <label>事件分类(三):</label>
                        </th>
                        <td align="left">
                            @{
                                List<SelectListItem> Applvl3 = new List<SelectListItem>();
                                Applvl3.Add(new SelectListItem { Text = "--------- 请选择 --------", Value = "0" });
                                @Html.DropDownList("Applvl3", Applvl3);
                            }
                        </td>
                        <td colspan="2"></td>
                    </tr>
                    <tr>
                        <td colspan="4">
                            【注】如果您在当前事件选项中没有找到ITSM事件分类，请在ITSM中维护添加该事件选择分类！
                        </td>
                    </tr>
                    <tr>
                        <td colspan="4">
                            <hr />
                        </td>
                    </tr>
                    <tr>
                        <th align="right"></th>
                        <td align="left">
                           <input class="Button1 ui-icons" type="button" id="createBtn" value="创建" style="margin-left: 45px; margin-top: 20px;" />
                        </td>
                        <th align="right">
                            
                        </th>
                        <td align="left">
                           
                        </td>
                    </tr>
                </tbody>
            </table>
            }
        </div>
    </div>
</div>
<div class="right_box_down ui-icons">
</div>
